function allNumber(v) {
    var reg = /^[0-9]*$/;
    if (reg.test(v)) {
        return true;
    }
    return false;
}

function CharMode(iN) {
    if (iN >= 48 && iN <= 57)//数字
        return 1;
    if (iN >= 65 && iN <= 90)//大写字母
        return 2;
    if (iN >= 97 && iN <= 122)//小写
        return 4;
    else
        return 8;//特殊字符
}

//计算出当前密码当中一共有多少种模式
function bitTotal(num) {
    var modes = 0;
    for (i = 0; i < 4; i++) {
        if (num & 1)
            modes++;
        num >>= 1;
    }
    return modes;
}

//返回密码的强度级别
function checkStrong(sPW) {
    if (sPW.length < 6)
        return 0;//密码太短
    var Modes = 0;
    for (i = 0; i < sPW.length; i++) {
        //测试每一个字符的类别并统计一共有多少种模式.
        Modes |= CharMode(sPW.charCodeAt(i));
    }
    //	alert(bitTotal(Modes));
    return bitTotal(Modes);
}


function showStrongPic() {
    var v = $("#pwd").val();
    var m = checkStrong(v);
    if (m < 2) {
        document.getElementById('lowPic').style.display = "";
        document.getElementById('midPic').style.display = "none";
        document.getElementById('highPic').style.display = "none";
    }
    else if (m == 2) {
        document.getElementById('lowPic').style.display = "none";
        document.getElementById('midPic').style.display = "";
        document.getElementById('highPic').style.display = "none";
    }
    else {
        document.getElementById('lowPic').style.display = "none";
        document.getElementById('midPic').style.display = "none";
        document.getElementById('highPic').style.display = "";
    }
}


//邮箱格式验证
function isEmail() {
    var email = document.getElementById('email').value;
    if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
        document.getElementById('email_re').innerHTML = li_ok;
        document.getElementById('email_re_m').innerHTML = '<span class=msg2>填写正确</span>';
        return true;
    }
    else {
        document.getElementById('email_re').innerHTML = li_err;
        document.getElementById('email_re_m').innerHTML = '<span class=msg>请填写正确的邮箱地址，格式为：123456@qq.com</span>';
        return false;
    }
}

//联系人
function isUserName() {
    var userName = document.getElementById('userName').value;
    if ((userName == null) || (userName == "")) {
        document.getElementById('userName_re').innerHTML = li_err;
        document.getElementById('userName_re_m').innerHTML = '<span class=msg>请填写用户姓名</span>';
        return false;
    }
    else {
        document.getElementById('userName_re').innerHTML = li_ok;
        document.getElementById('userName_re_m').innerHTML = '<span class=msg2>填写正确</span>';
        return true;
    }
}

//手机
function isMobile(){
    var mobile = $("#mobile").val();
    if ((mobile == null) || (mobile == "")) {
        document.getElementById('mobile_re').innerHTML = li_err;
        document.getElementById('mobile_re_m').innerHTML = '<span class=msg>请正确填写手机号码</span>';
        return false;
    }
    else {
        document.getElementById('mobile_re').innerHTML = li_ok;
        document.getElementById('mobile_re_m').innerHTML = '<span class=msg2>填写正确</span>';
        return true;
    }
}


//公司名
function isCompany() {
    var company = document.getElementById('company').value;
    if ((company == null) || (company == "")) {
        document.getElementById('company_re').innerHTML = li_err;
        document.getElementById('company_re_m').innerHTML = '<span class=msg>请正确填写公司名</span>';
        return false;
    }
    else {
        document.getElementById('company_re').innerHTML = li_ok;
        document.getElementById('company_re_m').innerHTML = '<span class=msg2>填写正确</span>';
        return true;
    }
}


//全表单提交验证
function tijiao() {
    if (isUserName() == false) {
        alert("用户名不正确，请重新填写！");
        document.regform.uname.focus();
        return false;
    }
    if (isMobile() == false) {
        alert("手机号不正确，请重新填写！");
        document.regform.mobile.focus();
        return false;
    }

    if (isEmail() == false) {
        alert("邮箱地址为空或者错误！");
        document.regform.email.focus();
        return false;
    }
    if (isCompany() == false) {
        alert("请填写公司全称！");
        document.regform.cname.focus();
        return false;
    }
}

//提交表单
function chk_reg() {
    if (tijiao() == false) {
        return false;
    }
    $.ajax({
        url:"/member/update",
        type:"post",
        data:$('#regform').serialize(),
        dataType:"json",
        success:function (data) {
            console.log(data);
            if (data.code == 0) {
                alert("修改成功");
                window.location.href = "/member/center";
            }
            else {
                alert(data.msg);
                return false;
            }
        },
        error:function (data) {
            console.log(data);
        }

    })
}

